using ASP;
using HoWave.Common;
using HoWave.Data;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Member_ClientRelation_ClientManage : Member, IRequiresSessionState
{
	private string linkHead = "";
	private string tabMenu = "";
	private string actionTab = "";
	private int clientId = 0;
	public string m_flag = "0";
	protected ScriptManager ScriptManager1;
	protected Label lblMyClient;
	protected Label lblAddpsn;
	protected Label lblAddcmp;
	protected Label Label2;
	protected DropDownList ddl_ClientType;
	protected DropDownList ddl_GroupID;
	protected DropDownList ddl_Area;
	protected DropDownList ddl_PeriodType;
	protected DropDownList ddl_IsBusiness;
	protected TextBox txtSearchClientName;
	protected Button SeachBut;
	protected GridView gvClient;
	protected Literal ltrPagePanel;
	protected Button btnMoreDelete;
	protected PlaceHolder PlaceHolder1;
	protected HiddenField hfIsRepeatKhName;
	protected HiddenField hfClientName;
	protected TextBox txtClientName;
	protected Label lblErr;
	protected TextBox txtClientNum;
	protected TextBox txtShortedForm;
	protected RequiredFieldValidator RequiredFieldValidator2;
	protected DropDownList ddl_ClientType1;
	protected DropDownList ddl_Area1;
	protected DropDownList ddl_ClientField1;
	protected DropDownList ddl_ValueLevel1;
	protected DropDownList ddl_CreditLevel1;
	protected DropDownList ddl_Importance1;
	protected DropDownList ddl_ConnectionLevel1;
	protected DropDownList ddl_GroupID1;
	protected RequiredFieldValidator RequiredFieldValidator3;
	protected DropDownList ddl_SourceType1;
	protected RequiredFieldValidator RequiredFieldValidator4;
	protected DropDownList ddl_PeriodType1;
	protected RequiredFieldValidator RequiredFieldValidator5;
	protected CheckBox chkIsBusiness;
	protected TextBox txtRemark;
	protected DropDownList ddl_Country;
	protected Shop_UserControls_HowaveProvinceCity HoWaveProvinceCity1;
	protected TextBox txtAddress;
	protected TextBox txtZipCode;
	protected RegularExpressionValidator revZipCode;
	protected TextBox txtHomePhone;
	protected TextBox txtFax;
	protected HiddenField h_ContacterID;
	protected HiddenField h_ClientID;
	protected TextBox txtTitle;
	protected DropDownList ddl_UserType;
	protected RadioButtonList rblSex;
	protected TextBox txtBirthday;
	protected TextBox txtNativePlace;
	protected TextBox txtNation;
	protected TextBox txtIDCard;
	protected RadioButtonList rblMarriage;
	protected TextBox txtFamily;
	protected DropDownList ddl_Income;
	protected DropDownList ddl_Education;
	protected TextBox txtGraduateFrom;
	protected TextBox txtInterestsOfLife;
	protected TextBox txtInterestsOfCulture;
	protected TextBox txtInterestsOfAmusement;
	protected TextBox txtInterestsOfSport;
	protected TextBox txtInterestsOfOther;
	protected TextBox txtCompany;
	protected TextBox txtCompanyAddress;
	protected TextBox txtDepartment;
	protected TextBox txtPosition;
	protected TextBox txtOperation;
	protected TextBox txtOfficePhone;
	protected TextBox txtMobile;
	protected TextBox txtEmail;
	protected TextBox txtQQ;
	protected TextBox txtMSN;
	protected TextBox txtYahoo;
	protected TextBox txtUC;
	protected TextBox txtHomepage;
	protected HtmlTable tb_person;
	protected HiddenField h_CompanyID;
	protected TextBox txtCompanyName;
	protected TextBox TextBox9;
	protected TextBox txtBankOfDeposit;
	protected TextBox txtBankAccount;
	protected TextBox txtTaxNum;
	protected DropDownList ddl_StatusInField;
	protected DropDownList ddl_CompanySize;
	protected TextBox txtBusinessScope;
	protected TextBox txtCompanyIntro;
	protected TextBox txtCompanyPic;
	protected TextBox txtRegisteredCapital;
	protected DropDownList ddl_ManagementForms;
	protected TextBox txtAnnualSales;
	protected HtmlTable tb_company;
	protected HiddenField HiddenField1;
	protected HiddenField HiddenField3;
	protected Repeater RepeaterContacter;
	protected Label lblRepeatErr;
	protected UpdatePanel UpdatePanel4;
	protected HtmlTable tb_company_contacter;
	protected Button ButtonAdd;
	protected PlaceHolder PlaceHolder2;
	protected TextBox txtZhuKehu;
	protected HtmlAnchor showZhuClient;
	protected HiddenField hfZhuKehu;
	protected TextBox txtCiKehu;
	protected HtmlAnchor showCiClient;
	protected HiddenField hfCiKehu;
	protected TextBox txtReason;
	protected Button ButtonMerge;
	protected Button btnBack;
	protected PlaceHolder PlaceHolder3;
	public string TabMenu
	{
		get
		{
			if (base.Request.QueryString["TabMenu"] != null)
			{
				this.tabMenu = base.Request.QueryString["TabMenu"].Trim();
			}
			return this.tabMenu;
		}
		set
		{
			this.tabMenu = value;
		}
	}
	public string ActionTab
	{
		get
		{
			if (base.Request.QueryString["action"] != null)
			{
				this.actionTab = base.Request.QueryString["action"].Trim();
			}
			else
			{
				this.actionTab = "";
			}
			return this.actionTab;
		}
		set
		{
			this.actionTab = value;
		}
	}
	public int ClientId
	{
		get
		{
			if (base.Request.QueryString["clientID"] != null)
			{
				this.clientId = Convert.ToInt32(base.Request.QueryString["clientID"].Trim());
			}
			return this.clientId;
		}
		set
		{
			this.clientId = value;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.OwnerPowerClientRelation(base.user.UserID))
			{
				base.WriteRightErrMsg();
			}
			this.ShowPanelDisplay(this.TabMenu);
			this.BindDropDownList();
			this.BindRadioButtonList();
			this.BindRepeater("1=2");
			if (this.ActionTab == "addinfo")
			{
				this.txtClientNum.Text = DateTime.Now.TimeString();
			}
			this.txtClientNum.ReadOnly = true;
			this.BindClient();
			this.InitPage();
		}
		else
		{
			this.m_flag = Cookie.GetCookie("ClientManage_m_flag");
		}
	}
	protected void BindRepeater(string where)
	{
		DataSet shortList = HoWave.Data.Bll.ClientContacter.instance.GetShortList(where);
		this.RepeaterContacter.DataSource = shortList.Tables[0];
		this.RepeaterContacter.DataBind();
	}
	protected void RepeaterContacter_ItemCommand(object source, RepeaterCommandEventArgs e)
	{
		int num = 0;
		if (e.CommandName == "del")
		{
			string text = e.CommandArgument.ToString();
			if (text != "")
			{
				int contacterID = Convert.ToInt32(text);
				HoWave.Data.Model.ClientContacter model = HoWave.Data.Bll.ClientContacter.instance.GetModel(contacterID);
				if (model != null)
				{
					num = Convert.ToInt32(model.ClientID);
					HoWave.Data.Bll.ClientContacter.instance.Delete(contacterID);
				}
				this.BindRepeater("ClientID=" + num);
			}
		}
		else
		{
			if (e.CommandName == "add")
			{
				int num2 = 0;
				if (this.ActionTab == "addinfo")
				{
					num2 = this.AddClientCom();
				}
				else
				{
					if (this.ActionTab == "editinfo")
					{
						num2 = Convert.ToInt32(this.h_ClientID.Value);
					}
				}
				if (num2 > 0)
				{
					if (this.ViewState["ClientID"] != null)
					{
						num = Convert.ToInt32(this.ViewState["ClientID"].ToString());
						TextBox textBox = (TextBox)e.Item.FindControl("TextBoxTrueName");
						TextBox textBox2 = (TextBox)e.Item.FindControl("TextBoxOfficePhone");
						TextBox textBox3 = (TextBox)e.Item.FindControl("TextBoxMobile");
						TextBox textBox4 = (TextBox)e.Item.FindControl("TextBoxQQ");
						TextBox textBox5 = (TextBox)e.Item.FindControl("TextBoxEmail");
						bool flag = true;
						this.lblRepeatErr.Text = "";
						if (textBox != null)
						{
							string text2 = textBox.Text.Trim();
							if (text2 == "")
							{
								textBox.Focus();
								this.lblRepeatErr.Text = "该联系人不能为空！";
								flag = false;
							}
							else
							{
								HoWave.Data.Model.ClientContacter contacterByTrueName = HoWave.Data.Bll.ClientContacter.instance.GetContacterByTrueName(text2);
								if (contacterByTrueName != null)
								{
									textBox.Focus();
									this.lblRepeatErr.Text = "该联系人已经存在了！";
									flag = false;
								}
							}
						}
						string text3 = textBox2.Text.Trim();
						string text4 = textBox3.Text.Trim();
						string a = textBox4.Text.Trim();
						string text5 = textBox5.Text.Trim();
						if (text3 == "" && text4 == "" && a == "" && text5 == "")
						{
							textBox2.Focus();
							Label expr_305 = this.lblRepeatErr;
							expr_305.Text += "联系方式至少填写一个！";
							flag = false;
						}
						else
						{
							if (text3 != "")
							{
								if (!PageValidate.CheckHomePhome(text3))
								{
									textBox2.Focus();
									Label expr_359 = this.lblRepeatErr;
									expr_359.Text += "办公电话格式不正确！";
									flag = false;
								}
							}
							else
							{
								if (text4 != "")
								{
									if (!PageValidate.CheckMobile(text4))
									{
										textBox2.Focus();
										Label expr_3AD = this.lblRepeatErr;
										expr_3AD.Text += "移动电话格式不正确！";
										flag = false;
									}
								}
								else
								{
									if (text5 != "")
									{
										if (!PageValidate.IsEmail(text5))
										{
											textBox5.Focus();
											Label expr_401 = this.lblRepeatErr;
											expr_401.Text += "Email地址格式不正确！";
											flag = false;
										}
									}
								}
							}
						}
						if (flag)
						{
							HoWave.Data.Model.ClientContacter clientContacter = new HoWave.Data.Model.ClientContacter();
							clientContacter.TrueName = textBox.Text;
							clientContacter.OfficePhone = textBox2.Text;
							clientContacter.Mobile = textBox3.Text;
							clientContacter.QQ = textBox4.Text;
							clientContacter.Email = textBox5.Text.Trim();
							clientContacter.ClientID = new int?(num);
							clientContacter.Owner = base.user.UserID;
							HoWave.Data.Bll.ClientContacter.instance.AddShort(clientContacter);
							this.BindRepeater("ClientID=" + num);
						}
					}
				}
			}
		}
	}
	private int AddClientCom()
	{
		int num = 0;
		if (this.CheckInput())
		{
			HoWave.Data.Model.Client client = this.GetClient();
			if (this.ViewState["ClientID"] == null)
			{
				client.LastVisitTime = null;
				client.LastRelationTime = new DateTime?(DateTime.Now);
				num = HoWave.Data.Bll.Client.instance.Add(client);
			}
			else
			{
				if (this.ViewState["ClientAddCom"] != null)
				{
					num = Convert.ToInt32(this.ViewState["ClientAddCom"]);
					HoWave.Data.Model.Client client2 = this.GetClient();
					client2.ClientID = Convert.ToInt32(this.ViewState["ClientID"].ToString());
					client2.LastVisitTime = null;
					bool flag = HoWave.Data.Bll.Client.instance.Update(client2);
				}
			}
			if (num > 0)
			{
				this.ViewState["ClientID"] = num;
				this.ViewState["ClientAddCom"] = num;
			}
		}
		return num;
	}
	protected void BindDropDownList()
	{
		this.ddl_ClientType.bindDataToDropDownList("HL_Client", "ClientType", false, false);
		this.ddl_GroupID.bindDataToDropDownList("HL_Client", "GroupID", false, false);
		this.ddl_Area.bindDataToDropDownList("HL_Client", "Area", false, false);
		this.ddl_PeriodType.bindDataToDropDownList("HL_Client", "PeriodType", false, false);
		this.ddl_IsBusiness.bindDataToDropDownList("HL_Client", "IsBusiness", false, false);
		this.ddl_ClientType1.bindDataToDropDownList("HL_Client", "ClientType", true, false);
		this.ddl_Area1.bindDataToDropDownList("HL_Client", "Area", true, false);
		this.ddl_ClientField1.bindDataToDropDownList("HL_Client", "ClientField", true, false);
		this.ddl_ValueLevel1.bindDataToDropDownList("HL_Client", "ValueLevel", true, false);
		this.ddl_CreditLevel1.bindDataToDropDownList("HL_Client", "CreditLevel", true, false);
		this.ddl_Importance1.bindDataToDropDownList("HL_Client", "Importance", true, false);
		this.ddl_ConnectionLevel1.bindDataToDropDownList("HL_Client", "ConnectionLevel", true, false);
		this.ddl_GroupID1.bindDataToDropDownList("HL_Client", "GroupID", true, false);
		this.ddl_SourceType1.bindDataToDropDownList("HL_Client", "SourceType", true, false);
		this.ddl_PeriodType1.bindDataToDropDownList("HL_Client", "PeriodType", true, false);
		this.ddl_UserType.bindDataToDropDownList("HL_ClientContacter", "UserType", true, false);
		this.ddl_Education.bindDataToDropDownList("HL_ClientContacter", "Education", true, false);
		this.ddl_StatusInField.bindDataToDropDownList("HL_ClientCompany", "StatusInField", true, false);
		this.ddl_CompanySize.bindDataToDropDownList("HL_ClientCompany", "CompanySize", true, false);
		this.ddl_ManagementForms.bindDataToDropDownList("HL_ClientCompany", "ManagementForms", true, false);
		this.ddl_Income.bindDataToDropDownList("HL_ClientContacter", "Income", true, false);
	}
	protected void BindRadioButtonList()
	{
		this.rblSex.bindDataToRadioButtonList("HL_ClientContacter", "Sex", true);
		this.rblMarriage.bindDataToRadioButtonList("HL_ClientContacter", "Marriage", true);
	}
	protected void ShowPanelDisplay(string DisplayName)
	{
		if (DisplayName != null)
		{
			if (!(DisplayName == "Myclient"))
			{
				if (!(DisplayName == "Addpsn"))
				{
					if (!(DisplayName == "Addcmp"))
					{
						if (DisplayName == "Merge")
						{
							this.m_flag = "3";
							this.PlaceHolder1.Visible = false;
							this.PlaceHolder2.Visible = false;
							this.PlaceHolder3.Visible = true;
							this.showZhuClient.Attributes.Add("onclick", "SelectZhu('" + this.txtZhuKehu.ClientID + "');");
							this.showCiClient.Attributes.Add("onclick", "SelectCi('" + this.txtCiKehu.ClientID + "');");
						}
					}
					else
					{
						this.m_flag = "2";
						this.PlaceHolder1.Visible = false;
						this.PlaceHolder2.Visible = true;
						this.tb_company_contacter.Visible = (this.tb_company.Visible = true);
						this.tb_person.Visible = false;
						this.ddl_ClientType1.Enabled = false;
						this.ddl_ClientType1.SelectedValue = HoWave.Data.Bll.Dictionary.instance.GetValueByText("企业客户");
						this.PlaceHolder3.Visible = false;
						if (this.ActionTab == "addinfo")
						{
							this.lblAddcmp.Text = "添加企业";
							this.txtClientName.Enabled = true;
						}
						else
						{
							if (this.ActionTab == "editinfo")
							{
								this.lblAddcmp.Text = "修改企业";
								this.txtClientName.Enabled = false;
							}
						}
					}
				}
				else
				{
					this.m_flag = "1";
					this.PlaceHolder1.Visible = false;
					this.PlaceHolder2.Visible = true;
					this.tb_company_contacter.Visible = (this.tb_company.Visible = false);
					this.tb_person.Visible = true;
					this.ddl_ClientType1.Enabled = false;
					this.ddl_ClientType1.SelectedValue = HoWave.Data.Bll.Dictionary.instance.GetValueByText("个人客户");
					this.PlaceHolder3.Visible = false;
					if (this.ActionTab == "addinfo")
					{
						this.lblAddpsn.Text = "添加个人";
						this.txtClientName.Enabled = true;
					}
					else
					{
						if (this.ActionTab == "editinfo")
						{
							this.lblAddpsn.Text = "修改个人";
							this.txtClientName.Enabled = false;
						}
					}
				}
			}
			else
			{
				this.m_flag = "0";
				this.PlaceHolder1.Visible = true;
				this.PlaceHolder2.Visible = false;
				this.PlaceHolder3.Visible = false;
			}
		}
		Cookie.SaveCookie("ClientManage_m_flag", this.m_flag, 0, "");
	}
	protected void ButtonAdd_Click(object sender, EventArgs e)
	{
		if (this.Page.IsValid && this.CheckInput())
		{
			if (this.ActionTab == "addinfo")
			{
				try
				{
					string text = this.TabMenu;
					if (text != null)
					{
						if (!(text == "Addpsn"))
						{
							if (text == "Addcmp")
							{
								int num = this.AddClientCom();
								if (num > 0)
								{
									if (this.RepeaterContacter.Items.Count <= 0)
									{
										MessageBox.Show(this, "请先执行联系人添加操作！");
										return;
									}
									HoWave.Data.Model.ClientCompany clientCompany = this.GetClientCompany();
									clientCompany.ClientID = new int?(num);
									int num2 = HoWave.Data.Bll.ClientCompany.instance.Add(clientCompany);
									if (num2 <= 0)
									{
										this.WriteErrMsg("", "写入公司信息失败！", "");
									}
									else
									{
										this.WriteSuccessMsg("", "添加企业客户成功！", "ClientManage.aspx?TabMenu=Myclient");
									}
								}
								else
								{
									this.WriteErrMsg("", "添加客户失败！", "");
								}
							}
						}
						else
						{
							HoWave.Data.Model.Client client = this.GetClient();
							client.LastVisitTime = null;
							client.LastRelationTime = new DateTime?(DateTime.Now);
							int num3 = HoWave.Data.Bll.Client.instance.Add(client);
							if (num3 > 0)
							{
								HoWave.Data.Model.ClientContacter clientContacter = this.GetClientContacter();
								clientContacter.ClientID = new int?(num3);
								int num4 = HoWave.Data.Bll.ClientContacter.instance.Add(clientContacter);
								if (num4 <= 0)
								{
									this.WriteErrMsg("", "个人信息失败！", "");
								}
								else
								{
									this.WriteSuccessMsg("", "添加个人客户成功！", "ClientManage.aspx?TabMenu=Myclient");
								}
							}
							else
							{
								this.WriteErrMsg("", "添加客户失败！", "");
							}
						}
					}
				}
				catch (Exception ex)
				{
					throw ex;
				}
			}
			else
			{
				if (this.ActionTab == "editinfo")
				{
					try
					{
						HoWave.Data.Model.Client client2 = this.GetClient();
						client2.ClientID = this.ClientId;
						client2.LastVisitTime = null;
						bool flag = HoWave.Data.Bll.Client.instance.Update(client2);
						if (flag)
						{
							string text = this.TabMenu;
							if (text != null)
							{
								if (!(text == "Addpsn"))
								{
									if (text == "Addcmp")
									{
										this.ViewState["ClientID"] = this.ClientId;
										if (this.RepeaterContacter.Items.Count <= 0)
										{
											MessageBox.Show(this, "请先执行联系人添加操作！");
											return;
										}
										if (!string.IsNullOrEmpty(this.h_CompanyID.Value))
										{
											HoWave.Data.Model.ClientCompany clientCompany2 = this.GetClientCompany();
											clientCompany2.ClientID = new int?(Convert.ToInt32(this.h_ClientID.Value));
											clientCompany2.CompanyID = Convert.ToInt32(this.h_CompanyID.Value);
											bool flag2 = HoWave.Data.Bll.ClientCompany.instance.Update(clientCompany2);
											if (flag2)
											{
												this.WriteSuccessMsg("", "更新企业客户信息成功！", "ClientManage.aspx?TabMenu=Myclient");
											}
											else
											{
												this.WriteErrMsg("", "更新企业客户信息失败！", "");
											}
										}
										else
										{
											this.WriteSuccessMsg("", "更新企业客户信息成功！", "ClientManage.aspx?TabMenu=Myclient");
										}
									}
								}
								else
								{
									if (this.h_ContacterID.Value != "")
									{
										HoWave.Data.Model.ClientContacter clientContacter2 = this.GetClientContacter();
										clientContacter2.ClientID = new int?(Convert.ToInt32(this.h_ClientID.Value));
										clientContacter2.ContacterID = Convert.ToInt32(this.h_ContacterID.Value);
										bool flag3 = HoWave.Data.Bll.ClientContacter.instance.Update(clientContacter2);
										if (flag3)
										{
											this.WriteSuccessMsg("", "更新个人客户信息成功！", "ClientManage.aspx?TabMenu=Myclient");
										}
										else
										{
											this.WriteErrMsg("", "更新个人客户信息失败！", "");
										}
									}
									else
									{
										HoWave.Data.Model.ClientContacter clientContacter = this.GetClientContacter();
										clientContacter.ClientID = new int?(this.ClientId);
										int num5 = HoWave.Data.Bll.ClientContacter.instance.Add(clientContacter);
										if (num5 <= 0)
										{
											this.WriteErrMsg("", "跟新个人信息失败！", "");
										}
										else
										{
											this.WriteSuccessMsg("", "更新个人客户信息成功！", "ClientManage.aspx?TabMenu=Myclient");
										}
									}
								}
							}
						}
						else
						{
							this.WriteErrMsg("", "更新客户信息失败！", "");
						}
					}
					catch (Exception ex)
					{
						throw ex;
					}
				}
			}
			this.txtClientNum.Text = DateTime.Now.TimeString();
			this.clearControls();
		}
	}
	protected HoWave.Data.Model.Client GetClient()
	{
		string text = this.txtClientNum.Text;
		string selectValue = this.ddl_ClientType1.GetSelectValue(new string[0]);
		string text2 = this.txtClientName.Text;
		string text3 = this.txtShortedForm.Text;
		string selectValue2 = this.ddl_Area1.GetSelectValue(new string[0]);
		string selectValue3 = this.ddl_ClientField1.GetSelectValue(new string[0]);
		string selectValue4 = this.ddl_ValueLevel1.GetSelectValue(new string[0]);
		string selectValue5 = this.ddl_CreditLevel1.GetSelectValue(new string[0]);
		string selectValue6 = this.ddl_Importance1.GetSelectValue(new string[0]);
		string selectValue7 = this.ddl_ConnectionLevel1.GetSelectValue(new string[0]);
		string selectValue8 = this.ddl_GroupID1.GetSelectValue(new string[0]);
		string selectValue9 = this.ddl_SourceType1.GetSelectValue(new string[0]);
		string selectValue10 = this.ddl_PeriodType1.GetSelectValue(new string[0]);
		string text4 = this.txtRemark.Text;
		int value = 0;
		int userID = base.user.UserID;
		string isBusiness = "IsBusiness_0";
		if (this.chkIsBusiness.Checked)
		{
			isBusiness = "IsBusiness_1";
		}
		return new HoWave.Data.Model.Client
		{
			ParentID = new int?(0),
			ClientNum = text,
			ClientType = selectValue,
			ClientName = text2,
			ShortedForm = text3,
			Area = selectValue2,
			ClientField = selectValue3,
			ValueLevel = selectValue4,
			CreditLevel = selectValue5,
			Importance = selectValue6,
			ConnectionLevel = selectValue7,
			GroupID = selectValue8,
			SourceType = selectValue9,
			PeriodType = selectValue10,
			Remark = text4,
			VisitTimes = new int?(value),
			CreateTime = new DateTime?(DateTime.Now),
			UpdateTime = new DateTime?(DateTime.Now),
			Owner = new int?(userID),
			IsBusiness = isBusiness
		};
	}
	protected HoWave.Data.Model.ClientContacter GetClientContacter()
	{
		HoWave.Data.Model.ClientContacter clientContacter = new HoWave.Data.Model.ClientContacter();
		string text = this.ddl_Country.Text;
		string selectedProvince = this.HoWaveProvinceCity1.SelectedProvince;
		string selectedCity = this.HoWaveProvinceCity1.SelectedCity;
		string selectedArea = this.HoWaveProvinceCity1.SelectedArea;
		string text2 = this.txtAddress.Text;
		string text3 = this.txtZipCode.Text;
		string text4 = this.txtHomePhone.Text;
		string text5 = this.txtFax.Text;
		clientContacter.Country = text;
		clientContacter.Province = selectedProvince;
		clientContacter.City = selectedCity;
		clientContacter.Districts = selectedArea;
		clientContacter.Address = text2;
		clientContacter.ZipCode = text3;
		clientContacter.HomePhone = text4;
		clientContacter.Fax = text5;
		string text6 = this.txtTitle.Text;
		string selectValue = this.ddl_UserType.GetSelectValue(new string[0]);
		string text7 = this.txtShortedForm.Text;
		string selectedValue = this.rblSex.SelectedValue;
		string text8 = this.txtBirthday.Text.Trim();
		string text9 = this.txtNativePlace.Text;
		string text10 = this.txtNation.Text;
		string text11 = this.txtIDCard.Text;
		string selectedValue2 = this.rblMarriage.SelectedValue;
		string text12 = this.txtFamily.Text;
		string selectValue2 = this.ddl_Income.GetSelectValue(new string[0]);
		string selectValue3 = this.ddl_Education.GetSelectValue(new string[0]);
		string text13 = this.txtGraduateFrom.Text;
		string text14 = this.txtInterestsOfLife.Text;
		string text15 = this.txtInterestsOfCulture.Text;
		string text16 = this.txtInterestsOfAmusement.Text;
		string text17 = this.txtInterestsOfSport.Text;
		string text18 = this.txtInterestsOfOther.Text;
		string text19 = this.txtCompany.Text;
		string text20 = this.txtDepartment.Text;
		string text21 = this.txtPosition.Text;
		string text22 = this.txtOperation.Text;
		string text23 = this.txtCompanyAddress.Text;
		string text24 = this.txtOfficePhone.Text;
		string text25 = this.txtMobile.Text;
		string text26 = this.txtEmail.Text;
		string text27 = this.txtHomepage.Text;
		string text28 = this.txtQQ.Text;
		string text29 = this.txtMSN.Text;
		string text30 = this.txtYahoo.Text;
		string text31 = this.txtUC.Text;
		DateTime now = DateTime.Now;
		DateTime now2 = DateTime.Now;
		clientContacter.Title = text6;
		clientContacter.UserType = selectValue;
		clientContacter.TrueName = text7;
		clientContacter.Sex = Convert.ToInt32(selectedValue);
		clientContacter.NativePlace = text9;
		clientContacter.Nation = text10;
		if (!string.IsNullOrEmpty(text8))
		{
			clientContacter.Birthday = new DateTime?(DateTime.Parse(text8));
		}
		clientContacter.IDCard = text11;
		clientContacter.Marriage = Convert.ToInt32(selectedValue2);
		clientContacter.Family = text12;
		clientContacter.Income = selectValue2;
		clientContacter.Education = selectValue3;
		clientContacter.GraduateFrom = text13;
		clientContacter.InterestsOfLife = text14;
		clientContacter.InterestsOfCulture = text15;
		clientContacter.InterestsOfAmusement = text16;
		clientContacter.InterestsOfSport = text17;
		clientContacter.InterestsOfOther = text18;
		clientContacter.Company = text19;
		clientContacter.Department = text20;
		clientContacter.Position = text21;
		clientContacter.Operation = text22;
		clientContacter.CompanyAddress = text23;
		clientContacter.Mobile = text25;
		clientContacter.OfficePhone = text24;
		clientContacter.Email = text26;
		clientContacter.Homepage = text27;
		clientContacter.QQ = text28;
		clientContacter.MSN = text29;
		clientContacter.Yahoo = text30;
		clientContacter.UC = text31;
		clientContacter.CreateTime = new DateTime?(now);
		clientContacter.UpdateTime = new DateTime?(now2);
		clientContacter.Owner = base.user.UserID;
		return clientContacter;
	}
	protected HoWave.Data.Model.ClientCompany GetClientCompany()
	{
		HoWave.Data.Model.ClientCompany clientCompany = new HoWave.Data.Model.ClientCompany();
		string text = this.ddl_Country.Text;
		string selectedProvince = this.HoWaveProvinceCity1.SelectedProvince;
		string selectedCity = this.HoWaveProvinceCity1.SelectedCity;
		string selectedArea = this.HoWaveProvinceCity1.SelectedArea;
		string text2 = this.txtAddress.Text;
		string text3 = this.txtZipCode.Text;
		string text4 = this.txtHomePhone.Text;
		string text5 = this.txtFax.Text;
		clientCompany.Country = text;
		clientCompany.Province = selectedProvince;
		clientCompany.City = selectedCity;
		clientCompany.Districts = selectedArea;
		clientCompany.Address = text2;
		clientCompany.ZipCode = text3;
		clientCompany.Phone = text4;
		clientCompany.Fax = text5;
		string text6 = this.txtCompanyName.Text;
		string text7 = this.txtHomepage.Text;
		string text8 = this.txtBankOfDeposit.Text;
		string text9 = this.txtBankAccount.Text;
		string text10 = this.txtTaxNum.Text;
		string selectValue = this.ddl_StatusInField.GetSelectValue(new string[0]);
		string selectValue2 = this.ddl_CompanySize.GetSelectValue(new string[0]);
		string businessScope = this.txtBusinessScope.Text.Trim();
		string text11 = this.txtAnnualSales.Text;
		string selectValue3 = this.ddl_ManagementForms.GetSelectValue(new string[0]);
		string text12 = this.txtRegisteredCapital.Text;
		string text13 = this.txtCompanyIntro.Text;
		string text14 = this.txtCompanyPic.Text;
		clientCompany.CompanyName = text6;
		clientCompany.Homepage = text7;
		clientCompany.BankOfDeposit = text8;
		clientCompany.BankAccount = text9;
		clientCompany.TaxNum = text10;
		clientCompany.StatusInField = selectValue;
		clientCompany.CompanySize = selectValue2;
		clientCompany.BusinessScope = businessScope;
		clientCompany.AnnualSales = text11;
		clientCompany.ManagementForms = selectValue3;
		clientCompany.RegisteredCapital = text12;
		clientCompany.CompanyIntro = text13;
		clientCompany.CompanyPic = text14;
		return clientCompany;
	}
	protected void BindClient()
	{
		HoWave.Data.Bll.Client client = new HoWave.Data.Bll.Client();
		string query = this.GetQuery();
		int num = this.gvClient.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = " from HL_Client as c where c.Owner=" + base.user.UserID + " ";
		ClientByPage clientByPage = new ClientByPage();
		int pageSize = this.gvClient.PageSize;
		int listCount = clientByPage.GetListCount("select count(*)" + text + query);
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		string str = " ROW_NUMBER() OVER (order by c.ClientID desc) as row,c.* ";
		string strSQL = "select " + str + text + query;
		DataTable listPage = clientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.gvClient.DataSource = listPage;
		this.gvClient.DataBind();
		string url = "ClientManage.aspx?TabMenu=Myclient" + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = CurrPageLinks.instance.CurrPageLinkStr(num, pageSize, listCount, "条记录&nbsp;&nbsp;每页&nbsp;" + pageSize + "&nbsp;条记录", url);
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("ClientType");
		if (!string.IsNullOrEmpty(text2))
		{
			this.ddl_ClientType.ddlSelect(text2);
		}
		else
		{
			text2 = this.ddl_ClientType.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and ClientType='" + text2 + "'";
			this.linkHead = this.linkHead + "&ClientType=" + text2;
		}
		string text3 = Fetch.Get("GroupID");
		if (!string.IsNullOrEmpty(text3))
		{
			this.ddl_GroupID.ddlSelect(text3);
		}
		else
		{
			text3 = this.ddl_GroupID.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text3))
		{
			text = text + " and GroupID='" + text3 + "'";
			this.linkHead = this.linkHead + "&GroupID=" + text3;
		}
		string text4 = Fetch.Get("Area");
		if (!string.IsNullOrEmpty(text4))
		{
			this.ddl_Area.ddlSelect(text4);
		}
		else
		{
			text4 = this.ddl_Area.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text4))
		{
			text = text + " and Area='" + text4 + "'";
			this.linkHead = this.linkHead + "&Area=" + text4;
		}
		string text5 = Fetch.Get("PeriodType");
		if (!string.IsNullOrEmpty(text5))
		{
			this.ddl_PeriodType.ddlSelect(text5);
		}
		else
		{
			text5 = this.ddl_PeriodType.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text5))
		{
			text = text + " and PeriodType='" + text5 + "'";
			this.linkHead = this.linkHead + "&PeriodType=" + text5;
		}
		string text6 = Fetch.Get("IsBusiness");
		if (!string.IsNullOrEmpty(text6))
		{
			this.ddl_IsBusiness.ddlSelect(text6);
		}
		else
		{
			text6 = this.ddl_IsBusiness.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text6))
		{
			text = text + " and IsBusiness='" + text6 + "'";
			this.linkHead = this.linkHead + "&IsBusiness=" + text6;
		}
		string text7 = Fetch.Get("KeHuName");
		if (!string.IsNullOrEmpty(text7))
		{
			this.txtSearchClientName.Text = text7;
		}
		else
		{
			text7 = this.txtSearchClientName.Text;
		}
		if (!string.IsNullOrEmpty(text7))
		{
			text = text + " and c.ClientName like '%" + text7 + "%'";
			this.linkHead = this.linkHead + "&KeHuName=" + text7;
		}
		return text;
	}
	protected string GetDictionaryTitle(string fieldValue)
	{
		string result = "";
		HoWave.Data.Model.Dictionary dictionary = HoWave.Data.Bll.Dictionary.instance.GetDictionary(fieldValue);
		if (dictionary != null)
		{
			result = dictionary.FieldText;
		}
		return result;
	}
	protected void gvClient_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void gvClient_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvClient.PageIndex = e.NewPageIndex;
		this.BindClient();
	}
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		string commandName = e.CommandName;
		string comeUrl = "ClientManage.aspx?TabMenu=Myclient" + this.linkHead + "&pageindex";
		if (commandName == "MoreDelete")
		{
			string text = Text.CheckNumList(Fetch.GetOrPost("IdSelect"));
			if (text != "")
			{
				bool flag = false;
				string text2 = text;
				string[] array = text2.Split(new char[]
				{
					','
				});
				for (int i = 0; i < array.Length; i++)
				{
					Member_ClientRelation_ClientManage.DelClientContacter(array[i]);
					flag = HoWave.Data.Bll.Client.instance.DeleteList(array[i]);
				}
				if (flag)
				{
					this.WriteErrMsg("", "批量信息删除成功！", comeUrl);
				}
			}
			else
			{
				this.WriteErrMsg("", "请选您要删除的信息", "");
			}
		}
		else
		{
			if (commandName == "CheckInfo")
			{
				string text3 = e.CommandArgument.ToString().Trim();
				if (!string.IsNullOrEmpty(text3))
				{
					string[] array2 = text3.Split(new string[]
					{
						","
					}, StringSplitOptions.RemoveEmptyEntries);
					if (array2.Length > 1)
					{
						string str = "&clientID=" + array2[1];
						if (array2[0].Trim() == "个人客户")
						{
							base.Response.Redirect("ClientDetailInfo.aspx?clientType=PersonType" + str);
						}
						else
						{
							if (array2[0].Trim() == "企业客户")
							{
								base.Response.Redirect("ClientDetailInfo.aspx?clientType=CompanyType" + str);
							}
						}
					}
				}
			}
			else
			{
				if (commandName == "EditInfo")
				{
					string text3 = e.CommandArgument.ToString().Trim();
					if (!string.IsNullOrEmpty(text3))
					{
						string[] array2 = text3.Split(new string[]
						{
							","
						}, StringSplitOptions.RemoveEmptyEntries);
						if (array2.Length > 1)
						{
							string str = "&action=editinfo&clientID=" + array2[1];
							if (array2[0].Trim() == "个人客户")
							{
								base.Response.Redirect("ClientManage.aspx?TabMenu=Addpsn" + str);
							}
							else
							{
								if (array2[0].Trim() == "企业客户")
								{
									base.Response.Redirect("ClientManage.aspx?TabMenu=Addcmp" + str);
								}
							}
						}
					}
				}
				else
				{
					if (commandName == "DelInfo")
					{
						string text4 = e.CommandArgument.ToString();
						Member_ClientRelation_ClientManage.DelClientContacter(text4);
						bool flag2 = HoWave.Data.Bll.Client.instance.Delete(Convert.ToInt32(text4));
						if (flag2)
						{
							this.WriteErrMsg("", "删除成功！", comeUrl);
						}
					}
				}
			}
		}
		this.BindClient();
	}
	private static void DelClientContacter(string delClientID)
	{
		DataTable contacterListByClientId = HoWave.Data.Bll.ClientContacter.instance.GetContacterListByClientId(Convert.ToInt32(delClientID));
		for (int i = 0; i < contacterListByClientId.Rows.Count; i++)
		{
			int contacterID = Convert.ToInt32(contacterListByClientId.Rows[i]["ContacterID"].ToString());
			HoWave.Data.Model.ClientContacter model = HoWave.Data.Bll.ClientContacter.instance.GetModel(contacterID);
			if (model != null)
			{
				bool flag = HoWave.Data.Bll.ClientContacter.instance.Delete(contacterID);
			}
		}
	}
	protected void SeachBut_Click(object sender, EventArgs e)
	{
		this.m_flag = "0";
		this.BindClient();
	}
	protected void InitPage()
	{
		if (this.ClientId > 0)
		{
			HoWave.Data.Model.Client model = HoWave.Data.Bll.Client.instance.GetModel(this.ClientId);
			if (model != null)
			{
				this.hfClientName.Value = model.ClientName;
				this.txtClientName.Text = model.ClientName;
				this.txtClientNum.Text = model.ClientNum;
				this.txtShortedForm.Text = model.ShortedForm;
				this.ddl_ClientType1.ddlSelect(model.ClientType);
				this.ddl_Area1.ddlSelect(model.Area);
				this.ddl_ClientField1.ddlSelect(model.ClientField);
				this.ddl_ValueLevel1.ddlSelect(model.ValueLevel);
				this.ddl_CreditLevel1.ddlSelect(model.CreditLevel);
				this.ddl_Importance1.ddlSelect(model.Importance);
				this.ddl_ConnectionLevel1.ddlSelect(model.ConnectionLevel);
				this.ddl_GroupID1.ddlSelect(model.GroupID);
				this.ddl_SourceType1.ddlSelect(model.SourceType);
				this.ddl_PeriodType1.ddlSelect(model.PeriodType);
				this.txtRemark.Text = model.Remark;
				string isBusiness = model.IsBusiness;
				if (isBusiness.Trim() == "IsBusiness_1")
				{
					this.chkIsBusiness.Checked = true;
				}
				else
				{
					this.chkIsBusiness.Checked = false;
				}
			}
			string text = this.TabMenu;
			if (text != null)
			{
				if (!(text == "Addpsn"))
				{
					if (text == "Addcmp")
					{
						HoWave.Data.Model.ClientCompany companyByClientID = HoWave.Data.Bll.ClientCompany.instance.GetCompanyByClientID(this.ClientId);
						this.ViewState["ClientID"] = this.ClientId;
						if (companyByClientID != null)
						{
							this.h_CompanyID.Value = companyByClientID.CompanyID.ToString();
							this.h_ClientID.Value = companyByClientID.ClientID.ToString();
							this.ddl_Country.ddlSelect(companyByClientID.Country);
							this.HoWaveProvinceCity1.SelectedProvince = companyByClientID.Province;
							this.HoWaveProvinceCity1.SelectedCity = companyByClientID.City;
							this.HoWaveProvinceCity1.SelectedArea = companyByClientID.Districts;
							this.txtAddress.Text = companyByClientID.Address;
							this.txtZipCode.Text = companyByClientID.ZipCode;
							this.txtHomePhone.Text = companyByClientID.Phone;
							this.txtFax.Text = companyByClientID.Fax;
							this.txtCompanyName.Text = companyByClientID.CompanyName;
							this.txtHomepage.Text = companyByClientID.Homepage;
							this.txtBankOfDeposit.Text = companyByClientID.BankOfDeposit;
							this.txtBankAccount.Text = companyByClientID.BankAccount;
							this.txtTaxNum.Text = companyByClientID.TaxNum;
							this.ddl_StatusInField.ddlSelect(companyByClientID.StatusInField);
							this.ddl_CompanySize.ddlSelect(companyByClientID.CompanySize);
							this.txtBusinessScope.Text = companyByClientID.BusinessScope;
							this.txtAnnualSales.Text = companyByClientID.AnnualSales;
							this.ddl_ManagementForms.ddlSelect(companyByClientID.ManagementForms);
							this.txtRegisteredCapital.Text = companyByClientID.RegisteredCapital;
							this.txtCompanyIntro.Text = companyByClientID.CompanyIntro;
							this.txtCompanyPic.Text = companyByClientID.CompanyPic;
						}
						this.BindRepeater("ClientID=" + this.ClientId);
					}
				}
				else
				{
					HoWave.Data.Model.ClientContacter contacterByClientId = HoWave.Data.Bll.ClientContacter.instance.GetContacterByClientId(this.ClientId, base.user.UserID);
					if (contacterByClientId != null)
					{
						this.h_ContacterID.Value = contacterByClientId.ContacterID.ToString();
						this.h_ClientID.Value = contacterByClientId.ClientID.ToString();
						this.ddl_Country.ddlSelect(contacterByClientId.Country);
						this.HoWaveProvinceCity1.SelectedProvince = contacterByClientId.Province;
						this.HoWaveProvinceCity1.SelectedCity = contacterByClientId.City;
						this.HoWaveProvinceCity1.SelectedArea = contacterByClientId.Districts;
						this.txtAddress.Text = contacterByClientId.Address;
						this.txtZipCode.Text = contacterByClientId.ZipCode;
						this.txtHomePhone.Text = contacterByClientId.HomePhone;
						this.txtFax.Text = contacterByClientId.Fax;
						this.ddl_UserType.ddlSelect(contacterByClientId.UserType);
						this.rblSex.rblSelect(contacterByClientId.Sex.ToString());
						this.txtTitle.Text = contacterByClientId.Title;
						this.txtNativePlace.Text = contacterByClientId.NativePlace;
						this.txtNation.Text = contacterByClientId.Nation;
						this.txtBirthday.Text = contacterByClientId.Birthday.ToString();
						this.txtIDCard.Text = contacterByClientId.IDCard;
						this.rblMarriage.rblSelect(contacterByClientId.Marriage.ToString());
						this.txtFamily.Text = contacterByClientId.Family;
						this.ddl_Income.ddlSelect(contacterByClientId.Income);
						this.ddl_Education.ddlSelect(contacterByClientId.Education);
						this.txtGraduateFrom.Text = contacterByClientId.GraduateFrom;
						this.txtInterestsOfLife.Text = contacterByClientId.InterestsOfLife;
						this.txtInterestsOfCulture.Text = contacterByClientId.InterestsOfCulture;
						this.txtInterestsOfAmusement.Text = contacterByClientId.InterestsOfAmusement;
						this.txtInterestsOfSport.Text = contacterByClientId.InterestsOfSport;
						this.txtInterestsOfOther.Text = contacterByClientId.InterestsOfOther;
						this.txtCompany.Text = contacterByClientId.Company;
						this.txtDepartment.Text = contacterByClientId.Department;
						this.txtPosition.Text = contacterByClientId.Position;
						this.txtOperation.Text = contacterByClientId.Operation;
						this.txtCompanyAddress.Text = contacterByClientId.CompanyAddress;
						this.txtMobile.Text = contacterByClientId.Mobile;
						this.txtOfficePhone.Text = contacterByClientId.OfficePhone;
						this.txtEmail.Text = contacterByClientId.Email;
						this.txtHomepage.Text = contacterByClientId.Homepage;
						this.txtQQ.Text = contacterByClientId.QQ;
						this.txtMSN.Text = contacterByClientId.MSN;
						this.txtYahoo.Text = contacterByClientId.Yahoo;
						this.txtUC.Text = contacterByClientId.UC;
					}
				}
			}
		}
	}
	protected void txtClientName_TextChanged(object sender, EventArgs e)
	{
		string text = this.txtClientName.Text.Trim();
		base.Response.Write(string.Concat(new string[]
		{
			"<br>A",
			this.hfClientName.Value,
			"A<br>B",
			text,
			"B"
		}));
		if (text != "")
		{
			HoWave.Data.Model.Client clientByClientName = HoWave.Data.Bll.Client.instance.GetClientByClientName(text, base.user.UserID);
			if (clientByClientName != null)
			{
				if (this.hfClientName.Value != text)
				{
					this.lblErr.Text = "客户名称不能重复";
				}
				else
				{
					this.lblErr.Text = "";
				}
			}
			else
			{
				this.lblErr.Text = "";
			}
		}
	}
	private void clearControls()
	{
		string cookie = Cookie.GetCookie("ClientManage_m_flag");
		string text = cookie;
		if (text != null)
		{
			if (!(text == "0"))
			{
				if (!(text == "1"))
				{
					if (!(text == "2"))
					{
						if (!(text == "3"))
						{
						}
					}
				}
			}
		}
	}
	private bool CheckInput()
	{
		bool result = true;
		string text = "";
		string text2 = this.txtClientName.Text.Trim();
		string text3 = this.TabMenu;
		if (text3 != null)
		{
			if (!(text3 == "Addpsn"))
			{
				if (text3 == "Addcmp")
				{
					if (this.txtCompanyName.Text.Trim() == "")
					{
						text += "公司名称不能为空！";
						this.txtCompanyName.Focus();
						MessageBox.Show(this, text);
						result = false;
					}
				}
			}
			else
			{
				if (this.ActionTab == "addinfo")
				{
					if (text2 != "")
					{
						HoWave.Data.Model.Client clientByClientName = HoWave.Data.Bll.Client.instance.GetClientByClientName(text2, base.user.UserID);
						if (clientByClientName != null)
						{
							MessageBox.Show(this, "客户名称不能重复！");
							result = false;
						}
					}
				}
				string text4 = this.txtIDCard.Text.Trim();
				if (text4 != "")
				{
					if (!PageValidate.CheckIDCard(text4))
					{
						this.txtIDCard.Focus();
						MessageBox.Show(this, "证件号码格式不正确！");
						result = false;
					}
				}
				string text5 = this.txtEmail.Text.Trim();
				if (text5 != "")
				{
					if (!PageValidate.IsEmail(text5))
					{
						this.txtEmail.Focus();
						MessageBox.Show(this, "Email地址格式不正确！");
						result = false;
					}
				}
			}
		}
		return result;
	}
	protected void ButtonMerge_Click(object sender, EventArgs e)
	{
		string text = this.hfZhuKehu.Value.Trim();
		string text2 = this.hfCiKehu.Value.Trim();
		bool flag = false;
		if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2))
		{
			string text3 = "";
			int num = 0;
			HoWave.Data.Model.Client clientByClientName = HoWave.Data.Bll.Client.instance.GetClientByClientName(text, base.user.UserID);
			if (clientByClientName != null)
			{
				text3 = this.GetDictionaryTitle(clientByClientName.ClientType);
				num = clientByClientName.ClientID;
			}
			string a = "";
			int num2 = 0;
			HoWave.Data.Model.Client clientByClientName2 = HoWave.Data.Bll.Client.instance.GetClientByClientName(text2, base.user.UserID);
			if (clientByClientName != null)
			{
				a = this.GetDictionaryTitle(clientByClientName2.ClientType);
				num2 = clientByClientName2.ClientID;
			}
			if (num == num2)
			{
				MessageBox.Show(this, "主客户和从客户是同一客户，不允许合并。");
			}
			else
			{
				string text4 = text3;
				if (text4 != null)
				{
					if (!(text4 == "个人客户"))
					{
						if (text4 == "企业客户")
						{
							if (a == "个人客户")
							{
								flag = this.MergeInfo(clientByClientName, clientByClientName2);
							}
							else
							{
								if (a == "企业客户")
								{
									flag = this.MergeInfo(clientByClientName, clientByClientName2);
								}
							}
						}
					}
					else
					{
						if (a == "个人客户")
						{
							flag = this.MergeInfo(clientByClientName, clientByClientName2);
						}
						else
						{
							if (a == "企业客户")
							{
								MessageBox.Show(this, "主客户是个人客户，从客户是企业客户，不允许合并。");
								return;
							}
						}
					}
				}
				if (flag)
				{
					this.WriteSuccessMsg("", "客户合并成功!", "ClientManage.aspx?TabMenu=Myclient");
				}
				else
				{
					this.WriteErrMsg("", "客户合并失败!", "");
				}
			}
		}
	}
	private bool MergeInfo(HoWave.Data.Model.Client zhuClient, HoWave.Data.Model.Client ciClient)
	{
		DataTable contacterListByClientId = HoWave.Data.Bll.ClientContacter.instance.GetContacterListByClientId(ciClient.ClientID);
		for (int i = 0; i < contacterListByClientId.Rows.Count; i++)
		{
			int contacterID = Convert.ToInt32(contacterListByClientId.Rows[i]["ContacterID"].ToString());
			HoWave.Data.Model.ClientContacter model = HoWave.Data.Bll.ClientContacter.instance.GetModel(contacterID);
			if (model != null)
			{
				model.ClientID = new int?(zhuClient.ClientID);
				bool flag = HoWave.Data.Bll.ClientContacter.instance.Update(model);
			}
		}
		HoWave.Data.Bll.ClientAnnal clientAnnal = new HoWave.Data.Bll.ClientAnnal();
		HoWave.Data.Model.ClientAnnal annalItem = clientAnnal.GetAnnalItem(" ClientID=" + ciClient.ClientID);
		if (annalItem != null)
		{
			annalItem.ClientID = zhuClient.ClientID;
			bool flag = clientAnnal.Update(annalItem);
		}
		HoWave.Data.Bll.ClientRemindItem clientRemindItem = new HoWave.Data.Bll.ClientRemindItem();
		HoWave.Data.Model.ClientRemindItem remindItem = clientRemindItem.GetRemindItem(" CorrelativeClient=" + ciClient.ClientID);
		if (remindItem != null)
		{
			remindItem.CorrelativeClient = new int?(zhuClient.ClientID);
			bool flag = clientRemindItem.Update(remindItem);
		}
		return HoWave.Data.Bll.Client.instance.Delete(ciClient.ClientID);
	}
	protected void btnBack_Click(object sender, EventArgs e)
	{
		string url = "ClientManage.aspx?TabMenu=Myclient" + this.linkHead + "&pageindex";
		base.Response.Redirect(url);
	}
	private void getClientByUser(string username)
	{
		if (username == base.user.UserName)
		{
			MessageBox.Show(this, "客户名称不能是当前用户");
		}
		else
		{
			string sql = "select *,u.Sex from HL_User u,HL_UserInfo ui where u.UserID=ui.UserID and u.UserName='" + username + "'";
			DataTable dataTable = this.conn.GetDataTable(sql);
			if (dataTable != null && dataTable.Rows.Count > 0)
			{
				DataRow dataRow = dataTable.Rows[0];
				string text = dataRow["TrueName"].ToString();
				int num = Convert.ToInt32(dataRow["UserID"].ToString());
				string text2 = this.TabMenu;
				if (text2 != null)
				{
					if (!(text2 == "Addpsn"))
					{
						if (!(text2 == "Addcmp"))
						{
						}
					}
					else
					{
						this.txtShortedForm.Text = text;
						this.ClientContacterByUserInfo(dataRow);
					}
				}
			}
		}
	}
	private void ClientContacterByUserInfo(DataRow drUser)
	{
		this.txtShortedForm.Text = drUser["TrueName"].ToString();
		this.ddl_Country.ddlSelect(drUser["Country"].ToString());
		this.HoWaveProvinceCity1.SelectedProvince = drUser["Province"].ToString();
		this.HoWaveProvinceCity1.SelectedCity = drUser["City"].ToString();
		this.HoWaveProvinceCity1.SelectedArea = drUser["CMArea"].ToString();
		this.txtAddress.Text = drUser["Address"].ToString();
		if (drUser["ZipCode"].ToString() != "0")
		{
			this.txtZipCode.Text = drUser["ZipCode"].ToString();
		}
		this.txtHomePhone.Text = drUser["HomePhone"].ToString();
		this.txtFax.Text = drUser["Fax"].ToString();
		if (drUser["Sex"] != DBNull.Value)
		{
			this.rblSex.rblSelect(drUser["Sex"].ToString());
		}
		this.txtTitle.Text = drUser["NickName"].ToString();
		this.txtNativePlace.Text = drUser["ComeFrom"].ToString();
		this.txtNation.Text = drUser["Nation"].ToString();
		if (!string.IsNullOrEmpty(drUser["Birthday"].ToString()))
		{
			this.txtBirthday.Text = drUser["Birthday"].ToString();
		}
		this.txtIDCard.Text = drUser["IDCard"].ToString();
		if (drUser["Marriage"] != DBNull.Value)
		{
			this.rblMarriage.rblSelect(drUser["Marriage"].ToString());
		}
		this.txtFamily.Text = drUser["Family"].ToString();
		this.ddl_Income.ddlSelect(drUser["InCome"].ToString());
		this.ddl_Education.ddlSelect(drUser["Eductation"].ToString());
		this.txtGraduateFrom.Text = drUser["GraduteSchool"].ToString();
		this.txtInterestsOfOther.Text = drUser["Interests"].ToString();
		this.txtMobile.Text = drUser["MobilePhone"].ToString();
		this.txtOfficePhone.Text = "";
		this.txtEmail.Text = drUser["Email"].ToString();
		this.txtHomepage.Text = drUser["HomePage"].ToString();
		this.txtQQ.Text = drUser["OICQ"].ToString();
		this.txtMSN.Text = drUser["MSN"].ToString();
	}
	private void ApplicationInfo(int IdentifyType, int userid)
	{
		string sql = string.Concat(new object[]
		{
			"select * from HLShop_Application where IdentifyType=",
			IdentifyType,
			" and Status=1 and UserID=",
			userid
		});
		DataTable dataTable = this.conn.GetDataTable(sql);
		if (dataTable != null && dataTable.Rows.Count >= 1)
		{
			if (IdentifyType == 2)
			{
				string[] contentArray = dataTable.Rows[0]["IdentifyDetail"].ToString().Split(new char[]
				{
					'$'
				});
				string contentByName = Shop_Application.GetContentByName("CompanylicenseUpload", contentArray);
				this.HoWaveProvinceCity1.SelectedProvince = Shop_Application.GetContentByName("CompanyProvince", contentArray);
				this.HoWaveProvinceCity1.SelectedCity = Shop_Application.GetContentByName("CompanyCity", contentArray);
				this.txtAddress.Text = Shop_Application.GetContentByName("CompanyAddress", contentArray);
				this.txtFax.Text = Shop_Application.GetContentByName("ContacterFax", contentArray);
				this.txtCompanyName.Text = Shop_Application.GetContentByName("CompanyName", contentArray);
				for (int i = 0; i < this.RepeaterContacter.Items.Count; i++)
				{
					Label label = (Label)this.RepeaterContacter.Items[i].FindControl("LabelTrueName");
					Label label2 = (Label)this.RepeaterContacter.Items[i].FindControl("LabelOfficePhone");
					Label label3 = (Label)this.RepeaterContacter.Items[i].FindControl("LabelMobile");
					Label label4 = (Label)this.RepeaterContacter.Items[i].FindControl("LabelQQ");
					Label label5 = (Label)this.RepeaterContacter.Items[i].FindControl("LabelEmail");
					TextBox textBox = (TextBox)this.RepeaterContacter.Items[i].FindControl("TextBoxTrueName");
					TextBox textBox2 = (TextBox)this.RepeaterContacter.Items[i].FindControl("TextBoxOfficePhone");
					TextBox textBox3 = (TextBox)this.RepeaterContacter.Items[i].FindControl("TextBoxMobile");
					TextBox textBox4 = (TextBox)this.RepeaterContacter.Items[i].FindControl("TextBoxQQ");
					TextBox textBox5 = (TextBox)this.RepeaterContacter.Items[i].FindControl("TextBoxEmail");
					Button button = (Button)this.RepeaterContacter.Items[i].FindControl("btnDelete");
				}
			}
		}
	}
}
